#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import os
import cairosvg
from PIL import Image
import io

def generate_favicon():
    """生成 favicon.ico"""
    # 读取 SVG 文件
    svg_path = os.path.join('web', 'static', 'icon.svg')
    with open(svg_path, 'rb') as f:
        svg_data = f.read()
    
    # 转换为 PNG
    png_data = cairosvg.svg2png(bytestring=svg_data, output_width=32, output_height=32)
    
    # 转换为 ICO
    img = Image.open(io.BytesIO(png_data))
    ico_path = os.path.join('web', 'static', 'favicon.ico')
    img.save(ico_path, format='ICO', sizes=[(32, 32)])

if __name__ == '__main__':
    generate_favicon() 